<div class="panel panel-default">
    <div class="panel-body">
        <div class="col-lg-8 col-lg-offset-2 " style="margin-top: 10px">
            <form class="form-horizontal" novalidate method="post" action="{% url 'userAdd' %}" id="add_user_form">
                {% csrf_token %}
                {% for field in form_obj %}
                    <div class="form-group {% if field.errors %}has-error{% endif %}">
                        <label for="{{ field.id_for_label }}"
                               class="col-sm-2 control-label">{{ field.label }}</label>
                        <div class="col-sm-10">
                            {{ field }}
                            <span class="help-block"> {{ field.errors.0 }}</span>
                        </div>
                    </div>
                {% endfor %}

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="reset" class="btn btn-primary reset-btn">清空</button>
                        <button class="btn btn-success save-btn" type="button">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{% block js %}
    <script>
        $("select").select2()
        $(".save-btn").on("click", function () {
            if ("{{ pk }}" == "0") {
                url = "{% url 'userAdd' %}"
            } else {
                url = "{% url "userEdit" pk %}"
            }
            Net.post({
                url: url,
                data: $("#add_user_form").serialize(),
                go: {% url 'userList' %}
            })
        })
    </script>
{% endblock %}